#include "StackQueue.h"





void test()
{
	ST data;
	StackInit(&data);
	StackPush(&data,1);
	StackPush(&data,2);
	StackPush(&data,3);


	while(!StackEmpty(&data))
	{
		printf("%d\n",StackTop(&data));
		StackPop(&data);
	}
	StackDestroy(&data);
}
typedef struct 
{
    ST pop;
    ST push;
} MyQueue;


MyQueue* myQueueCreate() 
{
    MyQueue* temp = (MyQueue*)malloc(sizeof(MyQueue));
    StackInit(&temp->push);
    StackInit(&temp->pop);
    return temp;
}

void myQueuePush(MyQueue* obj, int x)
{
    StackPush(&obj->push,x);
}

int myQueuePop(MyQueue* obj) 
{
	int temp;
    if(StackEmpty(&obj->pop))
    {
        while(!StackEmpty(&obj->push))
        {
            StackPush(&obj->pop,StackTop(&obj->push));
            StackPop(&obj->push);
        }
    }
    temp = StackTop(&obj->pop);
    StackPop(&obj->pop);
    return temp;
}


int myQueuePeek(MyQueue* obj) 
{
    if(StackEmpty(&obj->pop))
    {
        if(StackEmpty(&obj->pop))
        {
            while(!StackEmpty(&obj->push))
            {
                StackPush(&obj->pop,StackTop(&obj->push));
                StackPop(&obj->push);
            }
        }
    }
    int temp = StackTop(&obj->pop);
    return temp;
}

int myQueueEmpty(MyQueue* obj) 
{
    return (StackEmpty(&obj->pop) && StackEmpty(&obj->push));
}

void myQueueFree(MyQueue* obj) 
{
    StackDestroy(&obj->pop);
    StackDestroy(&obj->push);
    free(obj);
}


int main()
{
	//test();
	MyQueue* data= myQueueCreate();
	myQueuePush(data,1);
	myQueuePush(data,2);
	myQueuePush(data,3);
	printf("%d",myQueuePeek(data));

	return 0;
}